package com.fire.mokito.controller;

import com.fire.mokito.dao.UserDO;
import com.fire.mokito.service.UserService;
import com.fire.mokito.vo.UserVO;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.springframework.beans.BeanUtils.copyProperties;

/**
 * UserController
 *
 * @author zwd
 * @date 2022/5/15
 * @desc
 */
@RestController
@RequestMapping(value = "/user")
public class UserController {
    @Resource
    UserService userService;

    @GetMapping(value = "/detail")
    public List<UserVO> queryUsers(String name){
        List<UserDO> userDOS = userService.queryUsersByName(name);
        return userDOToVO(userDOS);
    }

    private List<UserVO> userDOToVO(List<UserDO> userDOS) {
        return userDOS.stream().map(userDO -> {
            UserVO userVO = new UserVO();
            copyProperties(userDO, userVO);
            return userVO;
        }).collect(Collectors.toList());
    }
}
